package com.cracker.websocket.server.service;

import lombok.Data;
import org.springframework.stereotype.Service;

/**
 * 统计服务,用于统计在线人数数据
 */
@Service
@Data
public class StatService {
    /**
     * 当前在线人数
     */
    private int onlineCount;
    /**
     * 最大在线人数
     */
    private int maxOnlineCount;

    public synchronized void incOnlineCount() {
        this.onlineCount++;
        this.maxOnlineCount = this.onlineCount > this.maxOnlineCount ? this.onlineCount : this.maxOnlineCount;
    }

    public synchronized void decOnlineCount() {
        this.onlineCount--;
    }

    public synchronized int getOnlineCount() {
        return onlineCount;
    }

}
